package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;

import dao.PeopleDao;
import domain.People;
import utils.JDBCUtil;

public class PeopleDaoImpl implements PeopleDao{

	@Override
	public void save(People people) {
		 Connection conn = null;
	        PreparedStatement ps = null;
	        try {
	            // 1.加载驱动
	            // 2.连接数据库
	            conn = JDBCUtil.getConn();
	            // 3.创建语句

	            String sql = "insert into people(name,age,sex,telephone) values(?,?,?,?)";
	            ps = conn.prepareStatement(sql);
	            ps.setString(1, people.getName());
	            ps.setInt(2, people.getAge());
	            ps.setString(3, people.getSex());
	            ps.setString(4, people.getTelephone());
	            // 4.执行语句
	            ps.executeUpdate();
	        } catch (Exception e) {
	            e.printStackTrace();
	        } finally {
	            // 5.释放资源
	            JDBCUtil.close(conn, ps, null);
	        }
	    }
	}